<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/basePath.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp" %>
<%@ include file="/classes/DBHelper.class.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String key = getParameter(request,"key");
	String queryType = getParameter(request,"queryType");
	
	String sql = "select t1.*,t2.type_name from APP_ZSPJ t1,APP_ZSPJ_TYPE t2 where t1.type_id = t2.guid";
	List<Object> params = new ArrayList<Object>();
	if(!nullOrEmpty(key)){
		pageContext.setAttribute("key",key);
		sql += " and (t1.question like ? or t1.answer like ?)";
		params.add("%"+key+"%");
		params.add("%"+key+"%");
	}
	if(!nullOrEmpty(queryType)){
		pageContext.setAttribute("queryType",queryType);
		sql +=" and t1.type_id = ?";
		params.add(queryType);
	}
	
	sql += " order by t1.pub_time desc";
	
	int currentPage = 1;
	if(!nullOrEmpty(getParameter(request,"currentPage"))){
		currentPage = Integer.valueOf(getParameter(request,"currentPage"));
	}
	
	List<Map<String,Object>> list = queryForListPage(sql,params,currentPage,10);
	pageContext.setAttribute("list",list);
	int total = queryForPageCount(sql,params);
	
	Map<String,Integer> m = new HashMap<String,Integer>();
	m.put("currentPage",currentPage);
	m.put("total",total);
	pageContext.setAttribute("page",m);
	
	String sqlListType = "select * from APP_ZSPJ_TYPE order by order_num";
	List<Map<String,Object>> listType = queryForList(sqlListType);
	pageContext.setAttribute("listType",listType);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="<%=basePath %>zspj/js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="<%=basePath %>zspj/js/jquery.form.js"></script>
<script type="text/javascript">
// $(document).ready(function() { 
//     $('#myForm').ajaxForm(function(data) {
//     	eval(data);//alert("评议成功！");
//     }); 
// });

function del(id){
	if(confirm("确定要删除？")){
		location.href = 'zspj_del.class.jsp?guid='+id;
	}
}
</script>
<link rel="stylesheet" type="text/css" href="../css/mytable.css"></link>
</head>
<body>
<form id="myForm" name="myForm" action="zspj_list.jsp?r=<%=new Date().getTime() %>" method="post" >
	<table cellspacing="0" width="700" > 
		<tr>
			<th>
				关键字：<input name="key" value="${key }"/>
			</th>
			<th>
				类型：<select name="queryType">
					<option value="">--请选择--</option>
					<c:forEach items="${listType }" var="type">
					<option value="${type.guid }" <c:if test="${type.guid==queryType }">selected="selected"</c:if> >${type.type_name }</option>
					</c:forEach>
				</select>
			</th>
			<th>
				<input type="submit" value="查询" />
				<input type="button" onclick="location.href = 'zspj_add.jsp?r=<%=new Date().getTime() %>'" value="新增" />
				<input type="button" onclick="location.href = 'zspj_type_list.jsp?r=<%=new Date().getTime() %>'" value="类型管理" />
			</th>
		</tr>
	</table>
	<table id="mytable" cellspacing="0" >
		<tr>
			<th  scope="col" width="300">问题</th>
			<th scope="col">答案 </th>
			<th scope="col" width="80">类型</th>
			<th scope="col" width="80">操作</th>
		</tr>
		<c:forEach items="${list }" var="zspj">
		<tr>
			<td scope="row">${zspj.question }</td>
			<td scope="row">${zspj.answer }</td>
			<td scope="row" align="center">${zspj.type_name }</td>
			<td scope="row" align="center">
			[<a href="zspj_modify.jsp?guid=${zspj.guid}&r=<%=new Date().getTime() %>">修改</a>]
			[<a href="javascript:del('${zspj.guid }')">删除</a>]</td>
		</tr>
		</c:forEach>
		<tr>
			<td colspan="4">
				<jsp:include page="/common/page.jsp">
					<jsp:param value="${page.currentPage }" name="currentPage"/>
					<jsp:param value="${page.total }" name="totalRecord"/>
					<jsp:param value="10" name="pageSize"/>
					<jsp:param value="myForm" name="formName"/>
				</jsp:include>
			</td>
		</tr>
	</table>
</form>
</body>
</html>